package cn.devzyh.oms.wsms.service.impl;

import cn.devzyh.oms.common.core.constant.CacheConstants;
import cn.devzyh.oms.common.core.util.RedisUtils;
import cn.devzyh.oms.wsms.api.entity.Channel;
import cn.devzyh.oms.wsms.mapper.ChannelMapper;
import cn.devzyh.oms.wsms.service.ChannelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Collection;

@Service
@RequiredArgsConstructor
public class ChannelServiceImpl extends ServiceImpl<ChannelMapper, Channel> implements ChannelService {

	@Cacheable(value = CacheConstants.CHANNEL_DETAIL, key = "#id")
	@Override
	public Channel getById(Serializable id) {
		return super.getById(id);
	}

	@CacheEvict(value = CacheConstants.CHANNEL_DETAIL, key = "#entity.code", condition = "#result")
	@Override
	public boolean save(Channel entity) {
		return super.save(entity);
	}

	@Override
	public boolean removeBatchByIds(Collection<?> list) {
		boolean res = super.removeBatchByIds(list);
		if (res) {
			RedisUtils.batchClearSpringCache(CacheConstants.CHANNEL_DETAIL, list);
		}
		return res;
	}

	@CacheEvict(value = CacheConstants.CHANNEL_DETAIL, key = "#entity.code", condition = "#result")
	@Override
	public boolean updateById(Channel entity) {
		return super.updateById(entity);
	}

}